from flask import Flask,make_response,request
app = Flask(__name__)
@app.route('/set_cookies', methods=['GET', 'POST'])
def set_cookies():#设置cookie
    resp=make_response("Hello Flask")
    #设置cookie有效期，浏览器关闭就失效
    resp.set_cookie("username","admin")
    #设置cookie有效期，max_age单位为秒
    resp.set_cookie("pwd","123456",max_age=60)
    print(resp.headers)
    return resp
@app.route("/get_cookies")
def get_cookies():# 获取cookie
    resp = request.cookies.get("username")
    print(type(resp))  # 类型为：str
    resp2 = request.cookies.get("pwd")
    print(type(resp2))  # 类型为：str
    print(resp)
    print(resp2)
    return resp
@app.route("/del_cookies")
def del_cookies():# 删除cookies
    resp = make_response("del")
    # 删除(过期)cookies
    resp.delete_cookie("pwd")
    print(resp.headers)
    return resp
if __name__ == '__main__':
    app.run()
